package cn.jiyun.controller;

import cn.jiyun.pojo.Student;
import cn.jiyun.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
public class StudentController {
    @Autowired
    StudentService studentService;

    @GetMapping("list")  //restfull  响应数据都是以json格式返回
    @ResponseBody
    public List<Student> findAll(){
        return studentService.findAll();
    }

    @RequestMapping("add")
    @ResponseBody
    public String insert (Student student){
        studentService.insert(student);
       return "day02";
    }
    @RequestMapping("update")
    @ResponseBody
    public String update(Student student){
        studentService.update(student);
        return  "day03";
    }
    @RequestMapping("delete")
    @ResponseBody
    public String delete(Integer id ){
       studentService.delete(id);
       return  "day04";
    }

        }

